//
//  MyCollectionViewController.m
//  Item A House
//
//  Created by dllo on 15/5/26.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MyCollectionViewController.h"
#import "OldCollectionModel.h"
#import "OldTwoViewController.h"

@interface MyCollectionViewController ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation MyCollectionViewController
- (void)dealloc
{
    [_array release];
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"二手房收藏";
        self.array = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64)];
    table.delegate = self;
    table.dataSource = self;
    table.rowHeight = 80;
    table.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
    [table release];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *arr = [OldCollectionModel readArray];
    self.array = [NSMutableArray arrayWithArray:arr];
    return [self.array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"sell"];
    }
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic = [self.array objectAtIndex:indexPath.row];
    cell.textLabel.text = [dic objectForKey:@"addrinfo"];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    OldTwoViewController *two = [[OldTwoViewController alloc]init];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic = [self.array objectAtIndex:indexPath.row];
    two.hid_id = [dic objectForKey:@"houseid"];
    [self.navigationController pushViewController:two animated:YES];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [OldCollectionModel deleteArray:indexPath.row];
//    [self.array removeObjectAtIndex:indexPath.row];
    [tableView reloadData];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
